package com.mall.service.commodity.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.PmsBrand;
import com.mall.service.commodity.service.PmsBrandService;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class PmsBrandController {
    @Autowired
    private PmsBrandService pmsBrandService;

    //添加品牌
    @PostMapping("/create")
    public CommonResult create(@RequestBody PmsBrand pmsBrand) {
        pmsBrandService.create(pmsBrand);
        return CommonResult.success(1, "创建成功");
    }

    //批量删除品牌
    @PostMapping("/delete/batch")
    public CommonResult deleteByIds(@RequestParam("ids") List<Long> ids) {
        pmsBrandService.deleteByIds(ids);
        return CommonResult.success(1, "批量删除成功");
    }

    //单体删除
    @GetMapping("/delete/{id}")
    public CommonResult deleteById(@PathVariable Long id) {
        pmsBrandService.deleteById(id);
        return CommonResult.success(1, "删除成功");
    }

    //根据品牌名称分页获取品牌列表
    @GetMapping("/list")
    public CommonResult<CommonPage> seleteList(String keyword, Integer pageNum, Integer pageSize) {

        CommonPage commonPage = pmsBrandService.seleteList(keyword, pageNum, pageSize);
        return CommonResult.success(commonPage);
    }

    //获取全部品牌列表
    @GetMapping("/listAll")
    public CommonResult<List> seleteAll() {
        List<PmsBrand> list = pmsBrandService.seleteAll();
        return CommonResult.success(list);
    }

    //批量更新厂家制造商状态
    @PostMapping("/update/factoryStatus")
    public CommonResult updateFactoryStatus(@RequestParam Integer factoryStatus,@RequestParam List<Long> ids) {
        pmsBrandService.updateFactory(factoryStatus, ids);
        return CommonResult.success(1, "更新成功");
    }

    //批量更新显示状态
    @PostMapping("/update/showStatus")
    public CommonResult updateShowStatus(@RequestParam Integer showStatus,@RequestParam List<Long> ids){
        pmsBrandService.updateShowStatus(showStatus,ids);
        return CommonResult.success(1, "更新成功");
    }

    //更新品牌
    @PostMapping("/update/{id}")
    public CommonResult updatePmsBrand(@PathVariable Long id,@RequestBody PmsBrand pmsBrand){
        pmsBrandService.updatePmsBrand(id,pmsBrand);
        return CommonResult.success(1,"更新成功");
    }

    //根据编号查询品牌信息
    @GetMapping("/{id}")
    public CommonResult<PmsBrand> findById(@PathVariable Long id){
        PmsBrand pmsBrand=pmsBrandService.findById(id);
        return CommonResult.success(pmsBrand);
    }

}
